Skip to content

Move asset hashing into a linker intercept step #3988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

ealmloff
Copy link
Member

@ealmloff ealmloff commented Apr 14, 2025

TODO:

  • Test linked bugs are fixed on wasm
  • Test linked bugs on Macos desktop
  • Test linked bugs on Windows desktop
  • Test linked bugs on Linux desktop

Fixes #3705
Fixes #3467
Fixes #3918

Stacked on #4042

@ealmloff ealmloff added cli Related to the dioxus-cli program manganis Related to the manganis crate bug Something isn't working labels Apr 14, 2025
@ealmloff ealmloff added the breaking This is a breaking change label Apr 30, 2025
@ealmloff ealmloff marked this pull request as ready for review May 5, 2025 12:07
@ealmloff ealmloff requested a review from a team as a code owner May 5, 2025 12:07
@ealmloff ealmloff marked this pull request as draft May 5, 2025 13:20
@ealmloff
Copy link
Member Author

ealmloff commented May 5, 2025

Because asset optimization is now a full linker step, it no longer works with the command added in #3429. If you want to use the dx asset optimizer outside of the CLI, you need to use the CLI as a linker like this (copied from the new help section):

Dioxus Asset Optimizer

When you serve dioxus with dx, it will automatically handle the build process for you. If you need to integrate with a larger build system,
you can use the dx asset optimizer separately to link to your assets. If you set the DX_LINK_ASSETS_TARGET environment variable, dx will
proxy your linker and copy the optimized assets it finds in your program into the specified directory.

Usage with trunk

If you are using trunk, you need to create a temporary asset directory to store the output of the dx asset optimizer that will be copied by trunk into your dist directory:

<html>
  <head>
    <link data-trunk rel="rust"/>
    <link data-trunk rel="copy-dir" href="./dist_assets/" data-target-path="./assets/"/>
  </head>
  <body>
    <div id="main"></div>
  </body>
</html>

Then when you build, you need to set the DX_LINK_ASSETS_TARGET environment variable to the path of the temporary asset directory and dx as your linker:

DX_LINK_ASSETS_TARGET="dist_assets" RUSTFLAGS="-Clinker=dx" trunk serve

Usage with cargo

If you are using cargo, you need to set the DX_LINK_ASSETS_TARGET environment variable to the path where your optimize assets will be stored and dx as your linker:

DX_LINK_ASSETS_TARGET="dist_assets" RUSTFLAGS="-Clinker=dx" cargo run

Custom linker path

DX will try to find the default linker for your system, but if you need to use a custom linker on top of the dx proxy, you can set the DX_LINKER environment variable to the path of your custom linker. For example, if you are using lld as your linker, you can set the DX_LINKER environment variable to the path of lld:

DX_LINKER="/path/to/lld" DX_LINK_ASSETS_TARGET="dist_assets" RUSTFLAGS="-Clinker=dx" cargo run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This is a breaking change bug Something isn't working cli Related to the dioxus-cli program manganis Related to the manganis crate
Projects
None yet
1 participant